package org.springblade.modules.platform.algorithm;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.platform.algorithm.method.*;
import org.springblade.modules.platform.dto.DeviceRuningStateDTO;
import org.springblade.modules.platform.entity.*;
import org.springblade.modules.platform.service.IAbsolutelyValueTableService;
import org.springblade.modules.platform.service.IDeviceTableService;
import org.springblade.modules.platform.service.IMeasuringPlatformTypeService;
import org.springblade.modules.platform.service.INoticeTableService;
import org.springblade.modules.platform.utils.TimeUtils;
import org.springblade.modules.platform.vo.MeasuringChainDetailsVO;
import org.springblade.modules.platform.vo.MeasuringPlatformVO;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.stream.Collectors;

@Component
@AllArgsConstructor
@Slf4j
public class CalculationMethod2 {

	private final IDeviceTableService iDeviceTableService;
	private final INoticeTableService iNoticeTableService;
	private final IMeasuringPlatformTypeService iMeasuringPlatformTypeService;
	private final BladeRedis bladeRedis;
	private final BaseStationMethod4 baseStation;
	private final BaseStationMethod5 baseStation2;
	private final BaseStationMethod6 baseStation3;
	private final IAbsolutelyValueTableService iAbsolutelyValueTableService;

	private static final Double NL = 156965.0;

	private static final Double ZL = 181350.0;




	public void getDeviceRuningState(List<DeviceRuningStateDTO> deviceRuningStateDTOs, Integer gatherEvent) {
		try {
			List<DeviceRuningStateDTO> collect = deviceRuningStateDTOs.stream().map(this::removeOutliers).filter(Objects::nonNull).collect(Collectors.toList());
			/*List<DeviceRuningStateDTO> deviceRuningStateDTOS = sl2(collect);*/
			for (DeviceRuningStateDTO x : collect) {
				List<AbsolutelyValueTable> list = iAbsolutelyValueTableService.list(Wrappers.<AbsolutelyValueTable>lambdaQuery().isNotNull(AbsolutelyValueTable::getBenchTypeCode));
				if(Func.isNotEmpty(list)){
					List<AbsolutelyValueTable> collect1 = list.stream().filter(l -> l.getMeasurChainDirection() == 1).collect(Collectors.toList());
					if(Func.isNotEmpty(collect1)){
						double x9 = 0.0;

						DeviceRuningStateDTO.DeviceListDTO deviceListDTO3 = x.getDeviceList().stream().filter(l -> l.getDeviceId().equals("26")).findFirst().orElse(null);

						double x26 = Double.parseDouble(deviceListDTO3.getAttributeListDTO().get(0).getValue().toString());
						if(x26<=1000||x26>=4000){
							continue;

						}


						AbsolutelyValueTable one1 = collect1.stream().filter(l -> l.getBenchTypeCode()==2526).findFirst().orElse(null);
						x9 = x9 + (((x26 - one1.getDipX()) / 100 )  * -1);


						DeviceRuningStateDTO.DeviceListDTO deviceListDTO27 = x.getDeviceList().stream().filter(l -> l.getDeviceId().equals("28")).findFirst().orElse(null);
						double x2728 = Double.parseDouble(deviceListDTO27.getAttributeListDTO().get(0).getValue().toString());
						if(x2728>=4000||x2728<=1000){
							continue;

						}


						AbsolutelyValueTable nOne = collect1.stream().filter(l -> l.getBenchTypeCode()==2728).findFirst().orElse(null);
						x9 = x9 + (((x2728 - nOne.getDipX()) / 100 )* -1);


						DeviceRuningStateDTO.DeviceListDTO deviceListDTO29 = x.getDeviceList().stream().filter(l -> l.getDeviceId().equals("29")).findFirst().orElse(null);
						double x29 = Double.parseDouble(deviceListDTO29.getAttributeListDTO().get(0).getValue().toString());
						AbsolutelyValueTable nOne29 = collect1.stream().filter(l -> l.getBenchTypeCode()==2930).findFirst().orElse(null);
						if(x29>=4000||x29<=1000){
							continue;

						}
						x9 = x9 + (((x29 - nOne29.getDipX()) / 100 ) * -1);

						DeviceRuningStateDTO.DeviceListDTO deviceListDTO32 = x.getDeviceList().stream().filter(l -> l.getDeviceId().equals("32")).findFirst().orElse(null);
						double x32 = Double.parseDouble(deviceListDTO32.getAttributeListDTO().get(0).getValue().toString());
						if(x32<=1000||x32>=4000){
							continue;

						}
						AbsolutelyValueTable nOne3132 = collect1.stream().filter(l -> l.getBenchTypeCode()==3132).findFirst().orElse(null);
						x9 = x9 + (((x32 - nOne3132.getDipX()) / 100 ) * -1);


						DeviceRuningStateDTO.DeviceListDTO deviceListDTO33 = x.getDeviceList().stream().filter(l -> l.getDeviceId().equals("34")).findFirst().orElse(null);
						double x34 = Double.parseDouble(deviceListDTO33.getAttributeListDTO().get(0).getValue().toString());
						if(x34<=1000||x34>=4000){
							continue;

						}
						AbsolutelyValueTable nOne3334 = collect1.stream().filter(l -> l.getBenchTypeCode()==3334).findFirst().orElse(null);
						x9 = x9 + ((x34 - nOne3334.getDipX()) / 100 );



						canThe9thOnBothSides3(x,x9,1);
					}else {
						canThe9thOnBothSides3(x,0.0,1);
					}

					List<AbsolutelyValueTable> absolutelyValueTable2 = list.stream().filter(l -> l.getMeasurChainDirection() == 2).collect(Collectors.toList());
					if(Func.isNotEmpty(absolutelyValueTable2)){

						double x9 = 0.0;

						DeviceRuningStateDTO.DeviceListDTO deviceListDTO3 = x.getDeviceList().stream().filter(l -> l.getDeviceId().equals("26")).findFirst().orElse(null);
						double x26 = Double.parseDouble(deviceListDTO3.getAttributeListDTO().get(0).getValue().toString());
						AbsolutelyValueTable one1 = absolutelyValueTable2.stream().filter(l -> l.getBenchTypeCode()==2526).findFirst().orElse(null);
						x9 = x9 + (((x26 - one1.getDipX()) / 100 )  * -1);


						DeviceRuningStateDTO.DeviceListDTO deviceListDTO27 = x.getDeviceList().stream().filter(l -> l.getDeviceId().equals("28")).findFirst().orElse(null);
						double x2728 = Double.parseDouble(deviceListDTO27.getAttributeListDTO().get(0).getValue().toString());
						AbsolutelyValueTable nOne = absolutelyValueTable2.stream().filter(l -> l.getBenchTypeCode()==2728).findFirst().orElse(null);
						x9 = x9 + (((x2728 - nOne.getDipX()) / 100 )* -1);


						DeviceRuningStateDTO.DeviceListDTO deviceListDTO29 = x.getDeviceList().stream().filter(l -> l.getDeviceId().equals("29")).findFirst().orElse(null);
						double x29 = Double.parseDouble(deviceListDTO29.getAttributeListDTO().get(0).getValue().toString());
						AbsolutelyValueTable nOne29 = absolutelyValueTable2.stream().filter(l -> l.getBenchTypeCode()==2930).findFirst().orElse(null);
						x9 = x9 + (((x29 - nOne29.getDipX()) / 100 ) * -1);

						DeviceRuningStateDTO.DeviceListDTO deviceListDTO32 = x.getDeviceList().stream().filter(l -> l.getDeviceId().equals("32")).findFirst().orElse(null);
						double x32 = Double.parseDouble(deviceListDTO32.getAttributeListDTO().get(0).getValue().toString());
						AbsolutelyValueTable nOne3132 = absolutelyValueTable2.stream().filter(l -> l.getBenchTypeCode()==3132).findFirst().orElse(null);
						x9 = x9 + (((x32 - nOne3132.getDipX()) / 100 ) * -1);


						DeviceRuningStateDTO.DeviceListDTO deviceListDTO33 = x.getDeviceList().stream().filter(l -> l.getDeviceId().equals("34")).findFirst().orElse(null);
						double x34 = Double.parseDouble(deviceListDTO33.getAttributeListDTO().get(0).getValue().toString());
						AbsolutelyValueTable nOne3334 = absolutelyValueTable2.stream().filter(l -> l.getBenchTypeCode()==3334).findFirst().orElse(null);
						x9 = x9 + ((x34 - nOne3334.getDipX()) / 100 );

						canThe9thOnBothSides3(x,x9,2);
					}else {
						canThe9thOnBothSides3(x,0.0,2);
					}

					//canThe9thOnBothSides3(x,(x9-absolutelyValueTable.getDipX())/100,1);

				}else {
					baseStation3.installDeviceRuningState(x, x.getGatherEvent(), 1, 0.0F);
					baseStation3.installDeviceRuningState(x, x.getGatherEvent(), 2, 0.0F);
				}
			}

		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}


	}
	public void canThe9thOnBothSides3(DeviceRuningStateDTO plumbDeviceStateDTO,Double x9,Integer measurChainDirection) {
		try {
			Double v2 = baseStation.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), 1, 0.0, measurChainDirection);
			if (measurChainDirection == 1) {
				double zGame = (x9 - v2) / ZL / 4.85E-6;
				Double v1 = baseStation.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), 1, zGame, measurChainDirection);
				if (v1 > x9) {//实际值比默认值小
					Integer x = 0;
					Double y = 1.0;
					Double vx = 0.0;
					while (true) {
						zGame = zGame + y;
						vx = baseStation.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), 1, zGame, measurChainDirection);
						if (x9 > vx) {///实际值比默认值大
							for (Double i = zGame - 1; i < zGame + 1; i = i + 0.1F) {
								baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), i, measurChainDirection);
							}
							baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), measurChainDirection, null);
							return;
						}
					}

				}else if (v1 < x9) {//实际值为负数 且大于测量值
					Integer x = 0;
					Double y = 1.0;
					Double vx1 = 0.0;
					while (true) {
						zGame = zGame - y;
						Double vx = baseStation.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), 1, zGame, measurChainDirection);
						if (x9 < vx) {///实际值比默认值大
							for (Double i = zGame - 1; i < zGame + 1; i = i + 0.1F) {
								baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), i, measurChainDirection);
							}
							baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), measurChainDirection, null);
							return;
						}
					}

				}else {

					baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection, (float) zGame);
					return;

				}

			} else {
				double zGame = (v2 - x9  ) / NL / 4.85E-6;
				Double v1 = baseStation.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), 1, zGame, measurChainDirection);
				if (v1 > x9) {//实际值比默认值小
					Integer x = 0;
					Double y = 1.0;
					Double vx = 0.0;
					while (true) {
						zGame = zGame - y;
						vx = baseStation.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), 1, zGame, measurChainDirection);
						if (x9 > vx) {///实际值比默认值大
							for (Double i = zGame - 1; i < zGame + 1; i = i + 0.1F) {
								baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), i, measurChainDirection);
							}
							baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), measurChainDirection, null);
							return;
						}
					}

				}else if (v1 < x9) {//实际值为负数 且大于测量值
					Integer x = 0;
					Double y = 1.0;
					Double vx = 0.0;
					while (true) {
						zGame = zGame + y;
						vx = baseStation.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), 1, zGame, measurChainDirection);
						if (x9 < vx) {///实际值比默认值大
							for (Double i = zGame - 1; i < zGame + 1; i = i + 0.1F) {
								baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), i, measurChainDirection);
							}
							baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), measurChainDirection, null);
							return;
						}
					}

				}else {

					baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection, (float) zGame);
					return;

				}
			}

		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}




	}
/*	public void canThe9thOnBothSides(DeviceRuningStateDTO plumbDeviceStateDTO,Double x9,Integer measurChainDirection){
		Double zGame = null;
		Object o = bladeRedis.get("device:game:" + measurChainDirection);//多少角秒
		if(o!=null){
			zGame = Double.parseDouble(o.toString());
		}
		Double v2 = baseStation.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), 1, zGame, measurChainDirection);
		if(x9>v2){//实际值比默认值大
			if(measurChainDirection==1){
				Integer x = 0;
				Float y = 1.0F;
				while(true){
					zGame = zGame - y;
					Double vx =  baseStation.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), 1, zGame ,measurChainDirection);
					if(x9<vx){
						for(Double i = zGame-1; i < zGame+1; i = i + 0.1F){
							baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,i,measurChainDirection);
						}
						baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,null);
						return;
					}else if(x9>vx){
						if(x>10){
							y = -1.0F;
							for(Float i = zGame-1; i < zGame+1; i = i + 0.1F){
								baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,i,measurChainDirection);
							}
							baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,null);
							return;
						}

					}else {
						if(x>10){
							if(zGame==null){
								zGame = 0.0F;
							}
							baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,zGame);
						}

					}
					x++;
				}
			}else {
				Integer x = 0;
				Float y = 1.0F;
				while(true){
					zGame = zGame - y;
					Double vx =  baseStation.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), 1, zGame ,measurChainDirection);
					if(x9<vx){
						for(Float i = zGame-1; i < zGame+1; i = i + 0.1F){
							baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,i,measurChainDirection);
						}
						baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,null);
						return;
					}else if(x9>vx){
						y = -1.0F;
						if(x>20){
							for(Float i = zGame-1; i < zGame+1; i = i + 0.2F){
								baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,i,measurChainDirection);
							}
							baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,null);
							return;
						}

					}else {
						if(x>10){
							if(zGame==null){
								zGame = 0.0F;
							}
							baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,zGame);
						}

					}
					x++;
				}
			}

		}else if(x9<v2){//实际值比默认值小
			if(measurChainDirection==1){
				Integer x = 0;
				Float y = 1.0F;
				while(true){
					zGame = zGame - y;
					Double vx =  baseStation.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), 1, zGame ,measurChainDirection);
					if(x9>vx){
						for(Float i = zGame-1; i < zGame+1; i = i + 0.1F){
							baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,i,measurChainDirection);
						}
						baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,null);
						return;
					}else if(x9<vx){
						y = 1.0F;
						if(x>10){
							for(Float i = zGame-1; i < zGame+1; i = i + 0.1F){
								baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,i,measurChainDirection);
							}
							baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,null);
							return;
						}

					}else {
						if(x>10){
							if(zGame==null){
								zGame = 0.0F;
							}
							baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,zGame);
						}
					}
					x++;
				}
			}else {
				Integer x = 0;
				Float y = 1.0F;
				while(true){
					zGame = zGame - y;
					Double vx =  baseStation.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent(), 1, zGame ,measurChainDirection);
					if(x9>vx){
						for(Float i = zGame-1; i < zGame+1; i = i + 0.1F){
							baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,i,measurChainDirection);
						}
						baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,null);
						return;
					}else if(x9<vx){
						y = 0.5F;
						if(x>10){
							for(Float i = zGame-1; i < zGame+1; i = i + 0.1F){
								baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,i,measurChainDirection);
							}
							baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,null);
							return;
						}

					}else {
						if(x>5){
							if(zGame==null){
								zGame = 0.0F;
							}
							baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,zGame);
						}

					}
					x++;
				}
			}

		}else {
			if(zGame==null){
				zGame = 0.0F;
			}
			baseStation3.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,measurChainDirection,zGame);
			return;

		}
	*//*	for(Float i = zGame-1; i < zGame+1; i = i + 0.1F){
			baseStation2.installDeviceRuningState(plumbDeviceStateDTO, plumbDeviceStateDTO.getGatherEvent() ,zGame,measurChainDirection);
		}*//*


	}*/

	/**
	 * 去掉异常点
	 * @param deviceRuningStateDTO
	 * @return
	 */
	public List<DeviceRuningStateDTO> sl2(List<DeviceRuningStateDTO> deviceRuningStateDTO){

		return 	deviceRuningStateDTO.stream().filter(x-> TimeUtils.getDateTimeOfTimestamp(x.getAcquisitionTime()).getHour()==4
			&&TimeUtils.getDateTimeOfTimestamp(x.getAcquisitionTime()).getMinute()<32).collect(Collectors.toList());
	}
	public DeviceRuningStateDTO removeOutliers(DeviceRuningStateDTO deviceRuningStateDTO){
/*		Long acquisitionTime = deviceRuningStateDTO.getAcquisitionTime();//采集时间
		Object o = bladeRedis.get("acquisitionTime:");
		if(o==null){
			bladeRedis.set("acquisitionTime:",acquisitionTime);
		}else {
			if((acquisitionTime-Long.parseLong(o.toString())>(1000*60*60*2))){
				bladeRedis.set("acquisitionTime:",acquisitionTime);
				return null;
			}
		}
		bladeRedis.set("acquisitionTime:",acquisitionTime);*/
		for (DeviceRuningStateDTO.DeviceListDTO x : deviceRuningStateDTO.getDeviceList()) {
			List<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> attributeListDTO = x.getAttributeListDTO();
			if(attributeListDTO.stream().map(DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO::getKey).collect(Collectors.toList()).contains("real_value")){
				continue;

			}
			Optional<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> ccd2AfterDipY1 = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd2_after_dip_y")).findFirst();
			if(!ccd2AfterDipY1.isPresent()){
				continue;
			}
			Optional<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> ccd2FrontDipY1 = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd2_front_dip_y")).findFirst();
			if(!ccd2FrontDipY1.isPresent()){
				continue;
			}

			DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO ccd2AfterDipY = ccd2AfterDipY1.get();
			DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO ccd2FrontDipY = ccd2FrontDipY1.get();

			if((ccd2AfterDipY.getValue()>7000||(ccd2AfterDipY.getValue()<=500&&ccd2AfterDipY.getValue()>0))&&
				(ccd2FrontDipY.getValue()>7000||(ccd2FrontDipY.getValue()<=500&&ccd2FrontDipY.getValue()>0))
			){
				DeviceTable one = iDeviceTableService.lambdaQuery()
					.eq(DeviceTable::getDeviceChannelId, x.getDeviceId())
					.eq(DeviceTable::getIsDeleted, 0).one();
				MeasuringPlatformType one1 = iMeasuringPlatformTypeService.getOne(Wrappers.<MeasuringPlatformType>lambdaQuery().like(MeasuringPlatformType::getDeviceId, one.getDeviceId()));
				NoticeTable noticeTable = new NoticeTable();
				noticeTable.setState(2);
				noticeTable.setEquipmentName(one1.getMeasuringPlatformName());
				noticeTable.setEquipmentId( x.getDeviceId());
				noticeTable.setGatherTime(deviceRuningStateDTO.getAcquisitionTime());
				noticeTable.setAlarmContent("CCD异常:"+ccd2AfterDipY.getKey()+":"+ccd2AfterDipY.getValue()+"||"+ccd2FrontDipY.getKey()+":"+ccd2FrontDipY.getValue());
				iNoticeTableService.save(noticeTable);
				return null;
			}
			Integer ccd1_x_after_backward = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd1_x_after_backward")).findFirst().get().getValue();
			Integer ccd1_x_front_backward = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd1_x_front_backward")).findFirst().get().getValue();
			Integer ccd4_x_after_backward = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd4_x_after_backward")).findFirst().get().getValue();
			Integer ccd4_x_front_backward = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd4_x_front_backward")).findFirst().get().getValue();

			if(!((ccd1_x_after_backward<7000&&ccd1_x_front_backward<7000&&ccd4_x_after_backward<7000&&ccd4_x_front_backward<7000)
				||(ccd1_x_front_backward>7000&&ccd4_x_front_backward>7000&&ccd1_x_after_backward<7000&&ccd4_x_after_backward<7000)
				||(ccd1_x_front_backward<7000&&ccd4_x_front_backward<7000&&ccd1_x_after_backward>7000&&ccd4_x_after_backward>7000)
			)){
				DeviceTable one = iDeviceTableService.lambdaQuery()
					.eq(DeviceTable::getDeviceChannelId, x.getDeviceId())
					.eq(DeviceTable::getIsDeleted, 0).one();
				MeasuringPlatformType one1 = iMeasuringPlatformTypeService.getOne(Wrappers.<MeasuringPlatformType>lambdaQuery().like(MeasuringPlatformType::getDeviceId, one.getDeviceId()));
				NoticeTable noticeTable = new NoticeTable();
				noticeTable.setState(2);
				noticeTable.setEquipmentName(one1.getMeasuringPlatformName());
				noticeTable.setEquipmentId( x.getDeviceId());
				noticeTable.setGatherTime(deviceRuningStateDTO.getAcquisitionTime());
				noticeTable.setAlarmContent("CCD异常:"+ccd2AfterDipY.getKey()+":"+ccd2AfterDipY.getValue()+"||"+ccd2FrontDipY.getKey()+":"+ccd2FrontDipY.getValue());
				iNoticeTableService.save(noticeTable);
				return null;
			}
/*			for (DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO y : attributeListDTO) {

				if(!y.getKey().equalsIgnoreCase("electricity")&&!y.getKey().equalsIgnoreCase("temperature")){
					if(y.getValue()>7000||(y.getValue()<=500&&y.getValue()>0)){
						DeviceTable one = iDeviceTableService.lambdaQuery()
							.eq(DeviceTable::getDeviceChannelId, x.getDeviceId())
							.eq(DeviceTable::getIsDeleted, 0).one();
						NoticeTable noticeTable = new NoticeTable();
						noticeTable.setState(2);
						noticeTable.setEquipmentName(one.getDeviceName());
						noticeTable.setEquipmentId( x.getDeviceId());
						noticeTable.setGatherTime(deviceRuningStateDTO.getAcquisitionTime());
						noticeTable.setAlarmContent("CCD异常:"+y.getKey()+":"+y.getValue());
						iNoticeTableService.save(noticeTable);
						return null;
					}
				}

			}*/
		}


		return deviceRuningStateDTO;
	}

}
